<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>广告分类管理</title>
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
	<script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>

	<script  src="/media/layui/layui.js" type="text/javascript"></script>

	<script type="text/javascript">
        //跳转页面
        function goPage(pageIndex) {
            $("#contentCategoryForm").attr("action","/contentCategory_page/"+pageIndex+"/5");
            $("#contentCategoryForm").submit();
        }

        //新增
        function addContent_category(){
            $.ajax({
                url:"/contentCategory_add",
                type:"post",
                dataType:"json",
                data:$("#addForm").serialize(),
                success:function(result){
                    alert(JSON.stringify(result));
                    layui.use('table', function() {
                        if(result.code=="601"){
                            layer.msg("新增成功", {icon : 6},function(){
                                window.location.reload();//刷新页面
                            });
                        }else{
                            layer.msg("新增失败", {icon : 5},function(){
                                window.location.reload();//刷新页面
                            });
                        }
                    });
                }
            });
        }

        //数据回显
        function getById(contentCategory_id){
            //根据ID查询一个对象绑定下拉框
            $.getJSON("/contentCategory_id",{"contentCategory_id":contentCategory_id},function (result) {
                //alert(JSON.stringify(result));
                $("#ContentCategoryName").val(result.name);
                $("#ContentCategoryId").val(result.id); //藏值
            });
        }

        //更新
        function editContent_category() {
            $.ajax({
                url:"/contentCategory_update",
                type:"post",
                dataType:"json",
                data:$("#editForm").serialize(),
                success:function(result){
                    //alert(JSON.stringify(result));
                    layui.use('table', function() {
                        if(result.code=="603"){
                            layer.msg("更新成功", {icon : 6},function(){
                                window.location.reload();//刷新页面
                            });
                        }else{
                            layer.msg("更新失败", {icon : 5},function(){
                                window.location.reload();//刷新页面
                            });
                        }
                    });
                }
            });
        }

        //根据ID删除
        function deleteById(id) {
            layui.use('table', function () {
                layer.confirm('是否确认删除该广告分类?', function (index) {
                    $.post("/contentCategory_deleteById/"+id,function (result) {
                        //alert(JSON.stringify(result));
                        if(result.code==602){
                            layer.msg("删除成功", {icon: 6},function () {
                                window.location.reload();//刷新
                            });
                        }else if(result.code==250){
                            layer.msg(result.message, {icon: 5});
                        } else {
                            layer.msg("删除失败", {icon: 5});
                        }
                    },"json");
                });
            });
        }

	</script>
    
</head>

<body class="hold-transition skin-red sidebar-mini"  >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">广告分类管理</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" title="新建" data-toggle="modal" data-target="#addModal" ><i class="fa fa-file-o"></i> 新建</button>
                                        <button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
                                        <button type="button" class="btn btn-default" title="开启" onclick='confirm("你确认要开启吗？")'><i class="fa fa-check"></i> 开启</button>
                                        <button type="button" class="btn btn-default" title="屏蔽" onclick='confirm("你确认要屏蔽吗？")'><i class="fa fa-ban"></i> 屏蔽</button>
                                        <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
							<form id="contentCategoryForm" action="/contentCategory_page/1/5">
								<div class="box-tools pull-right">
									<div class="has-feedback">
										名称：<input name="name" th:value="${name}"/><button type="submit" class="btn btn-default">查询</button>
									</div>
								</div>
							</form>

                            <!--工具栏/-->
							<!--数据列表-->
							<table id="dataList" class="table table-bordered table-striped table-hover dataTable">
								<thead>
								<tr>
									<th class="" style="padding-right:0px">
										<input id="selall" type="checkbox" class="icheckbox_square-blue">
									</th>
									<th class="sorting_asc">分类ID</th>
									<th class="sorting">分类名称</th>
									<th class="text-center">操作</th>
								</tr>
								</thead>
								<tbody>
								<tr th:each="contentCategory:${pageUtils.records}">
									<td><input  type="checkbox" ></td>
									<td th:text="${contentCategory.id}">1</td>
									<td th:text="${contentCategory.name}">首页轮播广告</td>
									<td class="text-center">
										<button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal" th:onclick="'getById('+${contentCategory.id}+');'">修改</button>
										<button type="button" class="btn bg-red btn-xs" data-toggle="modal" th:onclick="'deleteById('+${contentCategory.id}+');'">删除</button>
									</td>
								</tr>
								</tbody>
							</table>
							<!-- 分页组件 -->
							<div class="row">
								<div class="col-sm-6"><div class="dataTables_paginate paging_bootstrap" id="sample-table_paginate">
									<ul class="pagination">
										<li class="prev"><a href="#" th:onclick="'goPage('+${pageUtils.pageIndex==1?1:pageUtils.pageIndex-1}+')'">上一页</a></li>
										<li th:each="num:${pageUtils.numbers}" th:class="${pageUtils.pageIndex==num}? active"><a href="#" th:onclick="'goPage('+${num}+')'" th:text="${num}">1</a></li>
										<li class="next"><a href="#" th:onclick="'goPage('+${pageUtils.pageIndex==pageUtils.pageCount?pageUtils.pageIndex:pageUtils.pageIndex+1}+')'">下一页</a></li>
										<li class="next"><a href="#" th:text="|当前${pageUtils.pageIndex}/${pageUtils.pageCount}页|">XXXX</a></li>
										<li class="next"><a href="#" th:text="|共${pageUtils.totalCount}条|">XXXX</a></li>
									</ul>
								</div>
								</div>
							</div>
							<!-- 分页组件 -->
                        </div>
                        <!-- 数据表格 /-->
                     </div>
                    <!-- /.box-body -->
	            <!-- 分页 -->
				
				                
<!-- 编辑窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" >
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			<h3 id="myModalLabel">广告分类编辑</h3>
		</div>
		<div class="modal-body">							
			
			<table class="table table-bordered table-striped"  width="800px">
		      	<tr>
		      		<td>分类名称</td>
		      		<td><input  class="form-control" placeholder="分类名称">  </td>
		      	</tr>
		      	<tr>
		      		<td>分组</td>
		      		<td><input  class="form-control" placeholder="分组">  </td>
		      	</tr>	
			    <tr>
		      		<td>KEY</td>
		      		<td><input  class="form-control" placeholder="KEY">  </td>
		      	</tr>		      
		      	<tr>
		      		<td>是否有效</td>
		      		<td>
		      		 <input type="checkbox" class="icheckbox_square-blue" >
		      		</td>
		      	</tr>  	
			 </table>				
			
		</div>
		<div class="modal-footer">						
			<button class="btn btn-success" data-dismiss="modal" aria-hidden="true">保存</button>
			<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
		</div>
	  </div>
	</div>
</div>




  <!-- 新增窗口 -->
  <form id="addForm" method="post">
	  <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-dialog" >
			  <div class="modal-content">
				  <div class="modal-header">
					  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					  <h3 id="myModalLabel">广告分类新增</h3>
				  </div>
				  <div class="modal-body">
					  <table class="table table-bordered table-striped"  width="800px">
						  <tr>
							  <td>分类名称</td>
							  <td><input  class="form-control" placeholder="分类名称" name="name"/>  </td>
						  </tr>
					  </table>
				  </div>
				  <div class="modal-footer">
					  <button class="btn btn-success" data-dismiss="modal" aria-hidden="true" onclick="addContent_category();">新增</button>
					  <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
				  </div>
			  </div>
		  </div>
	  </div>
  </form>


</body>

</html>